package com.yijiaw.service;

import com.yijiaw.dao.AboutDAO;

import com.yijiaw.domain.About;

import java.util.List;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;

import org.springframework.transaction.annotation.Transactional;

/**
 * Spring service that handles CRUD requests for About entities
 * 
 */

@Service("AboutService")
@Transactional
public class AboutServiceImpl implements AboutService {

	/**
	 * DAO injected by Spring that manages About entities
	 * 
	 */
	@Autowired
	private AboutDAO aboutDAO;

	/**
	 * Instantiates a new AboutServiceImpl.
	 *
	 */
	public AboutServiceImpl() {
	}

	/**
	 */
	@Transactional
	public About findAboutByPrimaryKey(Integer id) {
		return aboutDAO.findAboutByPrimaryKey(id);
	}

	/**
	 * Delete an existing About entity
	 * 
	 */
	@Transactional
	public void deleteAbout(About about) {
		aboutDAO.remove(about);
		aboutDAO.flush();
	}

	/**
	 * Save an existing About entity
	 * 
	 */
	@Transactional
	public void saveAbout(About about) {
		About existingAbout = aboutDAO.findAboutByPrimaryKey(about.getId());

		if (existingAbout != null) {
			if (existingAbout != about) {
				existingAbout.setId(about.getId());
				existingAbout.setContent(about.getContent());
			}
			about = aboutDAO.store(existingAbout);
		} else {
			about = aboutDAO.store(about);
		}
		aboutDAO.flush();
	}

	/**
	 * Return all About entity
	 * 
	 */
	@Transactional
	public List<About> findAllAbouts(Integer startResult, Integer maxRows) {
		return new java.util.ArrayList<About>(aboutDAO.findAllAbouts(startResult, maxRows));
	}

	/**
	 * Return a count of all About entity
	 * 
	 */
	@Transactional
	public Integer countAbouts() {
		return ((Long) aboutDAO.createQuerySingleResult("select count(o) from About o").getSingleResult()).intValue();
	}

	/**
	 * Load an existing About entity
	 * 
	 */
	@Transactional
	public Set<About> loadAbouts() {
		return aboutDAO.findAllAbouts();
	}
}
